from flask import request
import json
from util.logger_utils import setup_logger

logger = setup_logger('web回调处理日志')

def json_callback():
    try:
        msg = request.get_json()
        logger.info(f'收到微信回调消息: {msg}')
        return msg, 200
    except Exception as e:
        logger.error(f'处理请求时发生错误: {e}')
        return text_callback()

def text_callback():
    try:
        msg = request.get_data(as_text=True)
        logger.info(f'收到微信回调消息: {msg}')
        return json.loads(msg), 200
    except Exception as e:
        logger.error(f'处理请求时发生错误: {e}')
        return 'Internal Server Error', 500
